package exceptions_and_assertions;

/**
 * Created with IntelliJ IDEA.
 * User: Sam
 * Date: 07/02/14
 * Time: 22:00
 * To change this template use File | Settings | File Templates.
 */
public class ExceptionsTest {

	public ExceptionsTest() {
	}

	public void execute() {
		try{
			System.out.println("reversed: " + reverse(""));
		}catch(Exception e) {
			System.out.println("Exception caught: " + e);
		} finally {
			System.out.println("Nothing to clear-up");
		}
	}

	public static String reverse(String str) throws Exception {
		System.out.println(str);

		if(str.length() == 0){
			throw new Exception("String is length 0");
		}

		String reversed = "";

		for(int i = 1; i <= str.length(); i++) {
			reversed += (str.charAt(str.length()-i));
		}

		return reversed;
	}
}
